/**
 * 
 */
package ar.com.gtug.model;

import java.util.LinkedList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Sequence;
import javax.jdo.annotations.SequenceStrategy;

/**
 * @author Juan M. Irungaray (juan@irungaray.com.ar)
 * 
 */
@PersistenceCapable
@Sequence(name="users",strategy=SequenceStrategy.CONTIGUOUS)
public class User {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String firstName;

	@Persistent
	private String lastName;
	
	@Persistent
	private String email;

	//solo tiene sentido si nos interesa que te unas o sigas a mas de un grupo
	@Persistent(defaultFetchGroup="true")
	private List<Long> suscribedChapters= new LinkedList<Long>();
	
	@Persistent
	private Long managedChapter=-1l;

	
	public User(String firstName, String lastName, String email) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}
	
	public void suscribeToGroup(Long groupId) {
		if(!suscribedChapters.contains(groupId)){
			suscribedChapters.add(groupId);			
		}
		
	}

	public void unSuscribeToGroup(Long groupId) {
		if(!suscribedChapters.contains(groupId)){
			suscribedChapters.remove(groupId);			
		}
		
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Long> getSuscribedChapters() {
		return suscribedChapters;
	}

	public void setSuscribedChapters(List<Long> suscribedChapters) {
		this.suscribedChapters = suscribedChapters;
	}

	public Long getManagedChapter() {
		return managedChapter;
	}

	public void setManagedChapter(Long managedChapter) {
		this.managedChapter = managedChapter;
	}

	public Long getId() {
		return id;
	}

	

}
